﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsAppTest.Class
{
    internal class SearchBarClass
    {
       
        public Panel panel = new Panel();
        public Label search = new Label();
        public ComboBox searchBox = new ComboBox();
        public TextBox searchText = new TextBox();
        public Button searchButton = new Button();
        public Label curTime = new Label();
        public Label Time = new Label();


        //时间控件设置
        public System.Windows.Forms.Timer timer=new System.Windows.Forms.Timer();


        public  SearchBarClass()
        {
            //panel 编辑区域
            panel.Left = 3;
            panel.Top = 0;
            panel.Anchor= AnchorStyles.Top | 
                          AnchorStyles.Left | 
                          AnchorStyles.Right;
            panel.Size = new Size(645,72);
            panel.Controls.Add(search);
            panel.Controls.Add(searchBox);
            panel.Controls.Add(searchText);
            panel.Controls.Add(searchButton);
            panel.Controls.Add(curTime);
            panel.Controls.Add(Time);
            //

            //search编辑区
            search.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            search.AutoSize = true;
            search.Font = new Font("Microsoft YaHei UI", 10.5F, FontStyle.Regular, GraphicsUnit.Point);
            search.Location = new Point(6, 29);
            search.Name = "searchlabel";
            search.Size = new Size(51, 20);
            search.TabIndex = 4;
            search.Text = "搜索栏";
            //

            //searchCombox编辑区
            searchBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            searchBox.FormattingEnabled = true;
            searchBox.Items.AddRange(new object[] { "1", "2", "3", "4", "5" });
            searchBox.Location = new Point(60, 27);
            searchBox.Name = "searchcomboBox";
            searchBox.Size = new Size(88, 25);
            searchBox.TabIndex = 2;
            //

            //searchTextBox编辑区
            searchText.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            searchText.ForeColor = SystemColors.WindowFrame;
            searchText.Location = new Point(154, 29);
            searchText.Name = "searchtextBox";
            searchText.Size = new Size(176, 23);
            searchText.TabIndex = 5;
            searchText.Text = "请输入搜索内容";
            searchText.Enter += searchText_enter;
            searchText.Leave += searchText_leave;
            //


            //searchButton编辑区
            searchButton.Location = new Point(336, 29);
            searchButton.Name = "searchbutton";
            searchButton.Size = new Size(75, 23);
            searchButton.TabIndex = 6;
            searchButton.Text = "搜索";
            searchButton.UseVisualStyleBackColor = true;
            //

            //curTime编辑区
            curTime.AutoSize = true;
            curTime.Font = new Font("Microsoft YaHei UI", 10.5F, FontStyle.Regular, GraphicsUnit.Point);
            curTime.Location = new Point(430, 29);
            curTime.Name = "curtimelabe";
            curTime.Size = new Size(79, 20);
            curTime.TabIndex = 7;
            curTime.Text = "当前时间：";
            //



            //Time编辑区
            Time.AutoSize = true;
            Time.Font = new Font("Microsoft YaHei UI", 10.5F, FontStyle.Regular, GraphicsUnit.Point);
            Time.Location = new Point(515, 29);
            Time.Name = "timelabel";
            Time.Size = new Size(50, 20);
            Time.TabIndex = 8;
            //Time.Text = "label3";
            Time.Text = DateTime.Now.ToString("G");

            /// timer
            timer.Tick += timer_Tick;//timer的事件触发
            timer.Interval = 1000;
            timer.Start();
            ///

            //

        }

        //searchTextBox点击事件
        private void searchText_enter(object sender, EventArgs e)
        {
            if (searchText.Text == "请输入搜索内容")
                searchText.Text = "";
            searchText.ForeColor = Color.Black;
        }

        private void searchText_leave(object sender, EventArgs e)
        {
            if (searchText.Text == "")
            {
                searchText.Text = "请输入搜索内容";
                searchText.ForeColor = Color.Gray;
            }

        }
        //

        //time事件
        private void timer_Tick(object sender, EventArgs e)
        {
            Time.Text = DateTime.Now.ToString("G");
        }

        //

    }
}
